import datetime

from flask import Flask, render_template, redirect
from World import worldMap
from Countrys import main
from GlobalData import WorldCOVID

app = Flask(__name__)

wn = WorldCOVID()

#世界地图和世界表格 127.0.0.1:5006
@app.route('/')
def mapWorld():
    url = 'https://api.inews.qq.com/newsqa/v1/automation/foreign/country/ranklist'
    worldMap(url)
    return render_template('全球国家数据(%s).html' % (datetime.date.today()))

#
@app.route('/index')
def index():
    return redirect(mapWorld())

#各国累计确诊病例趋势折线图 127.0.0.1:5006/manycountryconfirm
@app.route('/manycountryconfirm')
def manyCountryConfirm():
    main(name = 'confirm', type = 'value')
    return render_template('各国累计确诊病例趋势折线图.html')

#各国累计治愈病例趋势折线图 127.0.0.1:5006/manycountryheal
@app.route('/manycountryheal')
def manyCountryHeal():
    main(name = 'heal', type = 'value')
    return render_template('各国累计治愈病例趋势折线图.html')

#各国累计死亡病例趋势折线图 127.0.0.1:5006/manycountrydead
@app.route('/manycountrydead')
def manyCountryDead():
    main(name = 'dead', type = 'value')
    return render_template('各国累计死亡病例趋势折线图.html')

#各国累计确诊病例趋势折线图(对数) 127.0.0.1:5006/manycountryconfirmlog
@app.route('/manycountryconfirmlog')
def manyCountryConfirmLog():
    main(name = 'confirm', type = 'log')
    return render_template('各国累计确诊病例趋势折线图(对数).html')

#各国累计治愈病例趋势折线图(对数) 127.0.0.1:5006/manycountryheallog
@app.route('/manycountryheallog')
def manyCountryHealLog():
    main(name = 'heal', type = 'log')
    return render_template('各国累计治愈病例趋势折线图(对数).html')

#各国累计死亡病例趋势折线图(对数) 127.0.0.1:5006/manycountrydeadlog
@app.route('/manycountrydeadlog')
def manyCountryDeadLog():
    main(name = 'dead', type = 'log')
    return render_template('各国累计死亡病例趋势折线图(对数).html')

#各洲累计确诊病例柱状图 127.0.0.1:5006/world/continent
@app.route('/world/continent')
def worldContient():
    wn.contientData()
    return render_template('各洲累计确诊病例柱状图.html')

#今日各国新增确诊病例数量排名 127.0.0.1:5006/countryadd
@app.route('/countryadd')
def worldCountryAdd():
    wn.countryAddConfirmRankList()
    return render_template('每日国家新增确诊病例数量排名.html')

#全球历史确诊/治愈/死亡信息
#确诊 127.0.0.1:5006/world/information/confirm/
#治愈 127.0.0.1:5006/world/information/heal/
#死亡 127.0.0.1:5006/world/information/dead/
@app.route('/world/information/<name>/')
def worldInformation(name):
    wn.globalCumulativeHistory(name = name)
    return render_template('全球历史%s信息.html' % name)

#中国省份累计确诊病例示意图 127.0.0.1:5006/chinaData
@app.route('/chinaData')
def chinaData():
    wn.chinaTotalData()
    return render_template('中国省份累计确诊病例示意图.html')

#中国各省数据对比 127.0.0.1:5006/comparechina
@app.route('/comparechina')
def compareChina():
    wn.compareChina()
    return render_template('中国各省数据对比.html')

#美国各州数据对比 127.0.0.1:5006/compareamerica
@app.route('/compareamerica')
def compareAmerica():
    wn.compareAmerica()
    return render_template('美国各州数据对比.html')

#项目主函数，启动项目
if __name__ == '__main__':
    app.run(port = 5006)